package cc.rengu.redp.bizimpl.upmp.service.impl;


import cc.rengu.igas.bomp.facade.BompMchntQueryService;
import cc.rengu.igas.bomp.facade.bean.MchntAreaInfoBean;
import cc.rengu.igas.bomp.facade.bean.MchntInfoBean;
import cc.rengu.igas.bomp.facade.enums.BompMchntStatusEnum;
import cc.rengu.igas.bomp.facade.request.MchntAreaListQueryRequest;
import cc.rengu.igas.bomp.facade.request.MchntInfoListQueryRequest;
import cc.rengu.igas.bomp.facade.response.MchntAreaListQueryResponse;
import cc.rengu.igas.bomp.facade.response.MchntInfoListQueryResponse;
import cc.rengu.igas.momp.facade.*;
import cc.rengu.igas.momp.facade.base.Header;
import cc.rengu.igas.momp.facade.bean.CashierCashbackMcInfoBean;
import cc.rengu.igas.momp.facade.bean.CashierCashbackMcListInfoBean;
import cc.rengu.igas.momp.facade.bean.CashierCashbackToCashierDetailInfoBean;
import cc.rengu.igas.momp.facade.request.*;
import cc.rengu.igas.momp.facade.response.*;
import cc.rengu.igas.momp.facade.result.Result;
import cc.rengu.redp.bizimpl.enums.MompTxnNumEnum;
import cc.rengu.redp.bizimpl.upmp.common.BusinessContainer;
import cc.rengu.redp.bizimpl.upmp.service.ICashierMarketManagerService;
import cc.rengu.redp.bizimpl.upmp.service.IUpmpBMchntBaseInfoService;
import cc.rengu.redp.bizimpl.upmp.service.IUpmpSysParamService;
import cc.rengu.redp.bizimpl.upmp.vo.UpmpUserInfoVO;
import cc.rengu.redp.bizimpl.utils.Common;
import cc.rengu.redp.bizimpl.utils.CommonUtils;
import cc.rengu.redp.bizimpl.utils.DateUtils;
import cc.rengu.redp.common.domain.QueryRequest;
import cc.rengu.redp.common.exception.RedpException;
import com.alibaba.fastjson.JSON;
import com.baomidou.dynamic.datasource.annotation.DS;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.google.common.collect.Lists;
import org.apache.commons.collections4.CollectionUtils;
import org.apache.commons.lang3.StringEscapeUtils;
import org.apache.dubbo.config.annotation.DubboReference;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.*;

@DS("upmp")
@Service
public class CashierMarketManagerServiceImpl implements ICashierMarketManagerService {
    @Autowired
    private IUpmpBMchntBaseInfoService bMchntBaseInfoService;

    @Autowired
    private IUpmpSysParamService upmpSysParamService;

//    @DubboReference(version = "2.2.0", timeout = 3000, url = "dubbo://172.17.100.9:62145", check = false)
    @DubboReference(version = "${dubbo.protocol.momp.version}", check = false)
    QueryMcListInfoService queryMcListInfoService;

//    @DubboReference(version = "2.2.0", url = "dubbo://172.17.100.9:62145", check = false)
    @DubboReference(version = "${dubbo.protocol.momp.version}", check = false)
    QueryMcDetailInfoService queryMcDetailInfoService;

//    @DubboReference(version = "2.2.0", url = "dubbo://172.17.100.9:62145", check = false)
    @DubboReference(version = "${dubbo.protocol.momp.version}", check = false)
    EditMcDetailService editMcDetailService;

//    @DubboReference(version = "2.2.0", url = "dubbo://172.17.100.9:62145", check = false)
    @DubboReference(version = "${dubbo.protocol.momp.version}", check = false)
    PublishMcService publishMcService;

//    @DubboReference(version = "2.2.0", url = "dubbo://172.17.100.9:62145", check = false)
    @DubboReference(version = "${dubbo.protocol.momp.version}", check = false)
    ManageMcService manageMcService;

//    @DubboReference(version = "2.2.0", url = "dubbo://172.17.100.9:62145", check = false)
    @DubboReference(version = "${dubbo.protocol.momp.version}", check = false)
    QueryStatisticsService queryStatisticsService;

//    @DubboReference(version = "2.2.0", url = "dubbo://172.17.100.9:62145", check = false)
    @DubboReference(version = "${dubbo.protocol.momp.version}", check = false)
    QueryPublicInfoService queryPublicInfoService;

    public static Logger log = LoggerFactory.getLogger(CashierMarketManagerServiceImpl.class);

    /**
     * 获取法人机构营销活动账号
     */
    public Result<QueryInstitutionMcAccountInfoResponse> getMcAccountInfo() throws RedpException {
        Result<QueryInstitutionMcAccountInfoResponse> result = null;
        QueryInstitutionMcAccountInfoRequest queryParam = new QueryInstitutionMcAccountInfoRequest();
        try {
            // 获取当前登录用户信息
            UpmpUserInfoVO user = CommonUtils.getCurrentUser(upmpSysParamService);
            //设置报文头
            Header header = new Header();
            header.setVersion(BusinessContainer.BOMP_VERSION);
            header.setTransDate(CommonUtils.getCurrentDate("yyyyMMdd"));
            header.setTransTime(CommonUtils.getCurrentDate("HHmmss"));
            header.setTxnNum(MompTxnNumEnum.INSTITUTION_MCACCOUNT_INFO.getType());

            header.setBizType(BusinessContainer.IGAS_DEFAULT_BIZ_TYPE);
            header.setInstId(user.getInstId());
            header.setSrcSysId(BusinessContainer.MOMP_SRC_SYS_ID);
            header.setChanlId(BusinessContainer.MOMP_SRC_SYS_ID);
            header.setTraceNo(user.getInstId().substring(0, 3) + user.getOrgCode() + MompTxnNumEnum.INSTITUTION_MCACCOUNT_INFO.getType() + DateUtils.formatDate(new Date(), "yyyyMMddHHmmssSSS"));
            queryParam.setHeader(header);

            queryParam.setOrgId(user.getOrgCode());
            log.info("获取法人机构营销活动账号 请求报文：{}", JSON.toJSONString(queryParam));
            result = queryPublicInfoService.queryInsititutionMcAccountInfo(queryParam);
            if (null == result.getResult().getAcctInfoObk()) {
                result.getResult().setAcctInfoObk(new ArrayList<>());
            }
            log.info("获取法人机构营销活动账号 应答报文：{}", JSON.toJSONString(result));
        } catch (Exception e) {
            log.error("获取法人机构营销活动账号时系统异常:[{}]", e);
            throw new RedpException("获取法人机构营销活动账号");
        }
        if (!result.isSuccess()) {
            log.error("获取法人机构营销活动账号失败:result=[{}]", JSON.toJSONString(result));
            throw new RedpException("获取法人机构营销活动账号信息失败");
        }
        return result;
    }

    /**
     * 收银员返现规则配项查询
     */
    public Result<QueryCashierCashbackBonusRuleResponse> getBonusRuleList() throws RedpException {
        Result<QueryCashierCashbackBonusRuleResponse> result = null;
        QueryCashierCashbackBonusRuleRequest queryParam = new QueryCashierCashbackBonusRuleRequest();
        try {
            // 获取当前登录用户信息
            UpmpUserInfoVO user = CommonUtils.getCurrentUser(upmpSysParamService);
            String orgCode = getOrgCode(user.getOrgCode());
            //设置报文头
            Header header = new Header();
            header.setVersion(BusinessContainer.BOMP_VERSION);
            header.setTransDate(CommonUtils.getCurrentDate("yyyyMMdd"));
            header.setTransTime(CommonUtils.getCurrentDate("HHmmss"));
            header.setTxnNum(MompTxnNumEnum.CASHIERCASHBACK_BONUS_RULE.getType());

            header.setBizType(BusinessContainer.IGAS_DEFAULT_BIZ_TYPE);
            header.setInstId(user.getInstId());
            header.setSrcSysId(BusinessContainer.MOMP_SRC_SYS_ID);
            header.setChanlId(BusinessContainer.MOMP_SRC_SYS_ID);
            header.setTraceNo(user.getInstId().substring(0, 3) + orgCode + MompTxnNumEnum.CASHIERCASHBACK_BONUS_RULE.getType() + DateUtils.formatDate(new Date(), "yyyyMMddHHmmssSSS"));
            queryParam.setHeader(header);
            log.info("查询收银员返现积分规则 请求报文：{}", JSON.toJSONString(queryParam));
            result = queryPublicInfoService.queryCashierCashbackBonusRule(queryParam);
            log.info("查询收银员返现积分规则 应答报文：{}", JSON.toJSONString(result));
        } catch (Exception e) {
            log.error("查询收银员返现积分规则时系统异常:[{}]", e);
            throw new RedpException("查询收银员返现积分规则时系统异常");
        }
        if (!result.isSuccess()) {
            log.error("查询收银员返现积分规则失败:result=[{}]", JSON.toJSONString(result));
            throw new RedpException("查询收银员返现积分规则列表失败");
        }
        return result;
    }

    /**
     * 根据orgcode获取固定长度14位的orgCode
     * 超过14位截取前14位
     * 不够14位前面补0
     *
     * @param orgCode
     * @return
     */
    private String getOrgCode(String orgCode) {
        if (orgCode.length() >= 14) {
            return orgCode.substring(0, 14);
        }
        int length = orgCode.length();
        StringBuffer sb = null;
        while (length < 14) {
            sb = new StringBuffer();
            sb.append("0").append(orgCode);
            orgCode = sb.toString();
            length = orgCode.length();
        }
        return orgCode;
    }

    /**
     * 查询收银员返现活动List
     *
     * @param queryParam
     * @param request
     * @return
     */
    public IPage<CashierCashbackMcListInfoBean> getCashierMCList(QueryCashierCashbackMcListInfoRequest queryParam, QueryRequest request) throws RedpException {
        Result<QueryCashierCashbackMcListInfoResponse> result = null;
        try {
            // 获取当前登录用户信息
            UpmpUserInfoVO user = CommonUtils.getCurrentUser(upmpSysParamService);
            String orgCode = getOrgCode(user.getOrgCode());
            //设置入参
            queryParam.setQueryId(user.getId());
            queryParam.setQueryOrgId(user.getOrgCode());
            queryParam.setPageIndex(String.valueOf(request.getPageNum() - 1));
            queryParam.setPageSize(String.valueOf(request.getPageSize()));

            //设置报文头
            Header header = new Header();
            header.setVersion(BusinessContainer.BOMP_VERSION);
            header.setTransDate(CommonUtils.getCurrentDate("yyyyMMdd"));
            header.setTransTime(CommonUtils.getCurrentDate("HHmmss"));
            header.setTxnNum(MompTxnNumEnum.CASHIERCASHBACK_MC_LIST.getType());
            header.setBizType(BusinessContainer.IGAS_DEFAULT_BIZ_TYPE);
            header.setInstId(user.getInstId());
            header.setSrcSysId(BusinessContainer.MOMP_SRC_SYS_ID);
            header.setChanlId(BusinessContainer.MOMP_SRC_SYS_ID);
            header.setTraceNo(user.getInstId().substring(0, 3) + orgCode + MompTxnNumEnum.CASHIERCASHBACK_MC_LIST.getType() + DateUtils.formatDate(new Date(), "yyyyMMddHHmmssSSS"));
            queryParam.setHeader(header);
            log.info("查询收银员返现营销活动列表 请求报文{}", JSON.toJSONString(queryParam));
            result = queryMcListInfoService.queryCashierCashbackMcList(queryParam);
            log.info("查询收银员返现营销活动列表 应答报文{}", JSON.toJSONString(result));
        } catch (Exception e) {
            log.error("查询收银员返现营销活动列表时系统异常:[{}]", e);
            throw new RedpException("查询收银员返现营销活动列表时系统异常");
        }
        if (!result.isSuccess()) {
            log.error("查询收银员返现营销活动列表失败:result=[{}]", JSON.toJSONString(result));
            throw new RedpException("查询收银员返现营销活动列表失败");
        }
        // 应答
        Page<CashierCashbackMcListInfoBean> page = new Page<>();
        List<CashierCashbackMcListInfoBean> list = Lists.newArrayList();
        if (Common.isNotBlank(result) && CollectionUtils.isNotEmpty(result.getResult().getMcListInfo())) {
            list = result.getResult().getMcListInfo();
            page.setRecords(list);
            page.setTotal(Integer.parseInt(result.getResult().getTotalRows()));
        } else {
            log.info("查询收银员返现营销活动列表时没有返回数据:result=[{}]", JSON.toJSONString(result.getResult()));
            page.setRecords(list);
            page.setTotal(0);
        }
        return page;
    }

    /**
     * 查询收银员返现活动明细List
     *
     * @param queryParam
     * @param request
     * @return
     */
    public IPage<CashierCashbackToCashierDetailInfoBean> getCashierMCDetailList(QueryCashbackToCashierDetailRequest queryParam, QueryRequest request) throws RedpException {
        Result<QueryCashbackToCashierDetailResponse> result = null;
        try {
            // 获取当前登录用户信息
            UpmpUserInfoVO user = CommonUtils.getCurrentUser(upmpSysParamService);
            String orgCode = getOrgCode(user.getOrgCode());
            //设置入参
            queryParam.setQueryId(user.getId());
            queryParam.setQueryOrgId(user.getOrgCode());
            queryParam.setPageIndex(String.valueOf(request.getPageNum()));
            queryParam.setPageSize(String.valueOf(request.getPageSize()));
            //设置报文头
            Header header = new Header();
            header.setVersion(BusinessContainer.BOMP_VERSION);
            header.setTransDate(CommonUtils.getCurrentDate("yyyyMMdd"));
            header.setTransTime(CommonUtils.getCurrentDate("HHmmss"));
            header.setTxnNum(MompTxnNumEnum.CASHIERCASHBACK_DETAIL_QUERY.getType());
            header.setBizType(BusinessContainer.IGAS_DEFAULT_BIZ_TYPE);
            header.setInstId(user.getInstId());
            header.setSrcSysId(BusinessContainer.MOMP_SRC_SYS_ID);
            header.setChanlId(BusinessContainer.MOMP_SRC_SYS_ID);
            header.setTraceNo(user.getInstId().substring(0, 3) + orgCode + MompTxnNumEnum.CASHIERCASHBACK_DETAIL_QUERY.getType() + DateUtils.formatDate(new Date(), "yyyyMMddHHmmssSSS"));
            queryParam.setHeader(header);
            log.info("查询收银员返现营销活动明细列表 请求报文：{}", JSON.toJSONString(queryParam));
            result = queryStatisticsService.queryCashbackToCashierDetail(queryParam);
            log.info("查询收银员返现营销活动明细列表 应答报文：{}", JSON.toJSONString(result));
        } catch (Exception e) {
            log.error("查询收银员返现营销活动明细列表时系统异常:[{}]", e);
            throw new RedpException("查询收银员返现营销活动列表时系统异常");
        }
        if (!result.isSuccess()) {
            log.error("查询收银员返现营销活动明细列表失败:result=[{}]", JSON.toJSONString(result));
            throw new RedpException("查询收银员返现营销活动明细列表失败");
        }
        // 应答
        Page<CashierCashbackToCashierDetailInfoBean> page = new Page<>();
        List<CashierCashbackToCashierDetailInfoBean> list = Lists.newArrayList();
        if (Common.isNotBlank(result) && CollectionUtils.isNotEmpty(result.getResult().getCashbackDetailList())) {
            list = result.getResult().getCashbackDetailList();
            page.setRecords(list);
            page.setTotal(Integer.parseInt(result.getResult().getTotalRows()));
        } else {
            log.info("查询收银员返现营销活动明细列表时没有返回数据:result=[{}]", JSON.toJSONString(result.getResult()));
            page.setRecords(list);
            page.setTotal(0);
        }
        return page;
    }

    /**
     * 查询收银员返现活动 详情
     */
    public Result<QueryCashierCashbackMcDetailInfoResponse> getCashierMCDetail(QueryCashierCashbackMcDetailInfoRequest queryParam) throws RedpException {

        Result<QueryCashierCashbackMcDetailInfoResponse> result = null;
        try {
            // 获取当前登录用户信息
            UpmpUserInfoVO user = CommonUtils.getCurrentUser(upmpSysParamService);
            String orgCode = getOrgCode(user.getOrgCode());
            //设置入参
            queryParam.setQueryId(user.getId());
            queryParam.setQueryOrgId(user.getOrgCode());

            //设置报文头
            Header header = new Header();
            header.setVersion(BusinessContainer.BOMP_VERSION);
            header.setTransDate(CommonUtils.getCurrentDate("yyyyMMdd"));
            header.setTransTime(CommonUtils.getCurrentDate("HHmmss"));
            header.setTxnNum(MompTxnNumEnum.CASHIERCASHBACK_MC_DETAIL.getType());
            header.setBizType(BusinessContainer.IGAS_DEFAULT_BIZ_TYPE);
            header.setInstId(user.getInstId());
            header.setSrcSysId(BusinessContainer.MOMP_SRC_SYS_ID);
            header.setChanlId(BusinessContainer.MOMP_SRC_SYS_ID);
            header.setTraceNo(user.getInstId().substring(0, 3) + orgCode + MompTxnNumEnum.CASHIERCASHBACK_MC_DETAIL.getType() + DateUtils.formatDate(new Date(), "yyyyMMddHHmmssSSS"));
            queryParam.setHeader(header);
            log.info("查询收银员返现营销活动详情 请求报文：{}", JSON.toJSONString(queryParam));
            result = queryMcDetailInfoService.queryCashierCashbackMcDetailInfo(queryParam);
            log.info("查询收银员返现营销活动详情 应答报文：{}", JSON.toJSONString(result));
        } catch (Exception e) {
            log.error("查询收银员返现营销活动详情时系统异常:[{}]", e);
            throw new RedpException("查询收银员返现营销活动详情时系统异常");
        }
        if (!result.isSuccess()) {
            log.error("查询收银员返现营销活动详情失败:result=[{}]", JSON.toJSONString(result));
            throw new RedpException("查询收银员返现营销活动详情失败");
        }
        //---将getPointRuleData  格式转换
        QueryCashierCashbackMcDetailInfoResponse resultData = result.getResult();
        CashierCashbackMcInfoBean mcInfoObj = resultData.getMcInfoObj();
        mcInfoObj.setPointRuleData(StringEscapeUtils.escapeHtml4(mcInfoObj.getPointRuleData()));
        resultData.setMcInfoObj(mcInfoObj);
        result.setResult(resultData);
        return result;
    }

    /**
     * 保存、编辑、修改 收银员返现活动
     */
    public Result<EditCashierCashbackMcDetailResponse> EditCashierAgentMarket(EditCashierCashbackMcDetailRequest param) throws RedpException {
        Result<EditCashierCashbackMcDetailResponse> result = null;
        try {
            // 获取当前登录用户信息
            UpmpUserInfoVO user = CommonUtils.getCurrentUser(upmpSysParamService);
            String orgCode = getOrgCode(user.getOrgCode());
            //设置入参
            param.setQueryType("0"); //-- 0-银行人员(录入\审核\发布)
            param.setQueryRole("00");  //-- 00-银行录入
            param.setQueryId(user.getId());
            param.setQueryOrgId(user.getOrgCode());

            //设置报文头查询收银员返现营销活动列表
            Header header = new Header();
            header.setVersion(BusinessContainer.BOMP_VERSION);
            header.setTransDate(CommonUtils.getCurrentDate("yyyyMMdd"));
            header.setTransTime(CommonUtils.getCurrentDate("HHmmss"));
            header.setTxnNum(MompTxnNumEnum.CASHIERCASHBACK_MC_EDIT.getType());
            header.setBizType(BusinessContainer.IGAS_DEFAULT_BIZ_TYPE);
            header.setInstId(user.getInstId());
            header.setSrcSysId(BusinessContainer.MOMP_SRC_SYS_ID);
            header.setChanlId(BusinessContainer.MOMP_SRC_SYS_ID);
            header.setTraceNo(user.getInstId().substring(0, 3) + orgCode + MompTxnNumEnum.CASHIERCASHBACK_MC_EDIT.getType() + DateUtils.formatDate(new Date(), "yyyyMMddHHmmssSSS"));
            param.setHeader(header);
            log.info("编辑收银员返现营销活动 请求报文：{}", JSON.toJSONString(param));
            result = editMcDetailService.editCashierCashbackMcDetail(param);
            log.info("编辑收银员返现营销活动 应答报文：{}", JSON.toJSONString(result));
        } catch (Exception e) {
            log.error("编辑收银员返现营销活动时系统异常:[{}]", e);
            throw new RedpException("编辑收银员返现营销活动时系统异常");
        }
        return result;
    }

    /**
     * 审核退回
     */
    public Result<ManageCashierCashbackMcResponse> handleCashierAgentMarket(ManageCashierCashbackMcRequest param) throws RedpException {
        Result<ManageCashierCashbackMcResponse> result;
        try {
            // 获取当前登录用户信息
            UpmpUserInfoVO user = CommonUtils.getCurrentUser(upmpSysParamService);
            String orgCode = getOrgCode(user.getOrgCode());
            //设置入参
            param.setQueryId(user.getId());
            param.setQueryOrgId(user.getOrgCode());

            //设置报文头
            Header header = new Header();
            header.setVersion(BusinessContainer.BOMP_VERSION);
            header.setTransDate(CommonUtils.getCurrentDate("yyyyMMdd"));
            header.setTransTime(CommonUtils.getCurrentDate("HHmmss"));
            header.setTxnNum(MompTxnNumEnum.CASHIERCASHBACK_MC_MANAGER.getType());
            header.setBizType(BusinessContainer.IGAS_DEFAULT_BIZ_TYPE);
            header.setInstId(user.getInstId());
            header.setSrcSysId(BusinessContainer.MOMP_SRC_SYS_ID);
            header.setChanlId(BusinessContainer.MOMP_SRC_SYS_ID);
            header.setTraceNo(user.getInstId().substring(0, 3) + orgCode + MompTxnNumEnum.CASHIERCASHBACK_MC_MANAGER.getType() + DateUtils.formatDate(new Date(), "yyyyMMddHHmmssSSS"));
            param.setHeader(header);
            log.info("操作收银员返现营销活动 请求报文：{}", JSON.toJSONString(param));
            result = manageMcService.manageCashierCashbackMc(param);
            log.info("操作收银员返现营销活动 应答报文：{}", JSON.toJSONString(result));
        } catch (Exception e) {
            log.error("操作收银员返现营销活动时系统异常:[{}]", e);
            throw new RedpException("操作收银员返现营销活动时系统异常");
        }
        return result;
    }

    /**
     * 发布代收银员返现营销活动
     */
    public Result<PublishCashierCashbackMcResponse> publishCashierAgentMarket(PublishCashierCashbackMcRequest param) throws RedpException {
        Result<PublishCashierCashbackMcResponse> result = null;
        try {
            // 获取当前登录用户信息
            UpmpUserInfoVO user = CommonUtils.getCurrentUser(upmpSysParamService);
            //设置入参
            param.setQueryId(user.getId());
            param.setQueryOrgId(user.getOrgCode());

            //设置报文头
            Header header = new Header();
            header.setVersion(BusinessContainer.BOMP_VERSION);
            header.setTransDate(CommonUtils.getCurrentDate("yyyyMMdd"));
            header.setTransTime(CommonUtils.getCurrentDate("HHmmss"));
            header.setTxnNum(MompTxnNumEnum.CASHIERCASHBACK_MC_PUBLISH.getType());
            header.setBizType(BusinessContainer.IGAS_DEFAULT_BIZ_TYPE);
            header.setInstId(user.getInstId());
            header.setSrcSysId(BusinessContainer.MOMP_SRC_SYS_ID);
            header.setChanlId(BusinessContainer.MOMP_SRC_SYS_ID);
            header.setTraceNo(user.getInstId().substring(0, 3) + user.getOrgCode() + MompTxnNumEnum.CASHIERCASHBACK_MC_PUBLISH.getType() + DateUtils.formatDate(new Date(), "yyyyMMddHHmmssSSS"));
            param.setHeader(header);
            log.info("发布收银员返现营销活动 请求报文：{}", JSON.toJSONString(param));
            result = publishMcService.publishCashierCashbackMc(param);
            log.info("发布收银员返现营销活动 应答报文：{}", JSON.toJSONString(result));
        } catch (Exception e) {
            log.error("发布收银员返现营销活动时系统异常:[{}]", e);
            throw new RedpException("发布收银员返现营销活动时系统异常");
        }
        return result;
    }

    public Map<String, Object> queryMcNoList(UpmpUserInfoVO user, MchntInfoListQueryRequest request, BompMchntQueryService bompQueryService, String traceNo) {
        Map<String, Object> maps = null;
        try {
            MchntInfoListQueryRequest req = new MchntInfoListQueryRequest();
            String mchntNo = "".equals(request.getMchntNo()) ? "" : request.getMchntNo();
            String mchntName = "".equals(request.getMchntName()) ? "" : request.getMchntName();
            int pageIndex = 0;
            int pageSize = Integer.parseInt(BusinessContainer.ECP_PAGE_MAXROWS);
            req.setMchntNo(mchntNo);
            req.setMchntName(mchntName);
            req.setPageIndex(pageIndex);
            req.setPageSize(pageSize);
            req.setMchntStatus(BompMchntStatusEnum.NORMAL.getType());
            req.setUserId(user.getId());
            MchntInfoListQueryResponse resp = bMchntBaseInfoService.mchntInfoListQuery(user.getInstId(), user, req, traceNo);
            maps = new HashMap<String, Object>();
            if (Common.isNotBlank(resp)) {
                List<MchntInfoBean> list = resp.getMchntInfoList();

                if (CollectionUtils.isNotEmpty(list)) {
                    Map<String, String> map = new HashMap<String, String>();
                    List<Object> rst = new ArrayList<Object>();
                    for (MchntInfoBean mchnt : list) {

                        map = new HashMap<String, String>();
                        map.put("id", mchnt.getMchntNo());
                        map.put("name", mchnt.getMchntName());
                        map.put("orgId", mchnt.getSignInstId());
                        rst.add(map);
                    }
                    maps.put("results", rst);
                    maps.put("more", false);
                    maps.put("totalPage", resp.getTotalPage());
                    maps.put("totalRows", resp.getTotalRows());
                }
            }
        } catch (Exception e) {
            log.error("查询商户信息时系统异常:[{}]", e);
//            throw new Exception("查询商户信息时系统异常");
        }
        return maps;
    }

    public Map<String, Object> queryMchntAreaList(UpmpUserInfoVO user, MchntAreaListQueryRequest request, BompMchntQueryService bompQueryService, String traceNo) {
        MchntAreaListQueryRequest req = new MchntAreaListQueryRequest();
        String mchntArea = "".equals(request.getMchntArea()) ? "" : request.getMchntArea();
        String mchntAreaName = "".equals(request.getMchntAreaName()) ? "" : request.getMchntAreaName();
        int pageIndex = 0;
        int pageSize = Integer.parseInt(BusinessContainer.ECP_PAGE_MAXROWS);
        req.setMchntArea(mchntArea);
        req.setMchntAreaName(mchntAreaName);
        req.setPageIndex(pageIndex);
        req.setPageSize(pageSize);
        req.setUserId(user.getId());
        MchntAreaListQueryResponse resp = null;
        try {
            resp = bMchntBaseInfoService.mchntAreaListQuery(user.getInstId(), user, req, bompQueryService, traceNo);
        } catch (RedpException e) {
            log.error("查询失败", e);
            return null;
        }
        Map<String, Object> maps = new HashMap<String, Object>();
        if (Common.isNotBlank(resp)) {
            List<MchntAreaInfoBean> list = resp.getMchntAreaInfoList();

            if (CollectionUtils.isNotEmpty(list)) {
                Map<String, String> map = new HashMap<String, String>();
                List<Object> rst = new ArrayList<Object>();
                for (MchntAreaInfoBean area : list) {

                    map = new HashMap<String, String>();
                    map.put("id", area.getMchntArea());
                    map.put("name", area.getMchntAreaName());
                    map.put("orgId", area.getSignInstId());
                    rst.add(map);
                }
                maps.put("results", rst);
                maps.put("more", false);
                maps.put("totalPage", resp.getTotalPage());
                maps.put("totalRows", resp.getTotalRows());
            }
        }
        return maps;
    }
}
